package com.amado.course36ByteStream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class S05FileOutPutStreamJava {
	public static void main(String[] args) throws IOException {
		OutputStream outputStream= null;
		try {
			File file = new File("D:\\temp1\\temp2\\Student.java");
			//父路径是否存在  D:\\temp1\\temp2
			if(!file.getParentFile().exists()) {
				//创建路径  D:\\temp1\\temp2
				file.getParentFile().mkdirs();
			}
			//不存在D:\\temp1\\temp2\\out.txt
			if(!file.exists()) {
				//创建文件 D:\\temp1\\temp2\\out.txt
				file.createNewFile();
			}
//			outputStream = new FileOutputStream(file);
			//true在文件后表示追加，false 会覆盖之前的内容
			outputStream = new FileOutputStream(file,true);
			//字符串转换为byte[]
			
			String content = "public class Student"
					+ "private Long id,private String name}";
			outputStream.write(content.getBytes());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			outputStream.close();
		}
	}
}
